package com.shangrila.biz.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.shangrila.biz.dao.CarefullyChosenItemsDao;
import com.shangrila.biz.pojo.CarefullyChosenItems;

public class DefaultCarefullyChosenItemsDao extends SqlMapClientDaoSupport implements CarefullyChosenItemsDao{

	@Override
	public void save(CarefullyChosenItems carefullyChosenItems){
		if (carefullyChosenItems.getCategoryLevel1() == null || carefullyChosenItems.getCategoryLevel2() == null
				|| carefullyChosenItems.getItemId() == null || carefullyChosenItems.getShowDate() == null) {
			throw new IllegalArgumentException("category and item_id and show_date cat't be null when save carefullyChosenItems");
		}
		getSqlMapClientTemplate().insert("DefaultCarefullyChosenItemsDao.save",carefullyChosenItems);
	}

	@Override
	public boolean update(CarefullyChosenItems carefullyChosenItems){
		if (carefullyChosenItems.getId() == null
				|| carefullyChosenItems.getCategoryLevel1() == null || carefullyChosenItems.getCategoryLevel2() == null
				|| carefullyChosenItems.getItemId() == null || carefullyChosenItems.getShowDate() == null) {
			throw new IllegalArgumentException("id or category or item_id cat't be null when update carefullyChosenItems");
		}
		return getSqlMapClientTemplate().update("DefaultCarefullyChosenItemsDao.update",carefullyChosenItems) > 0;
	}

	@Override
	public boolean delete(long id){
		return getSqlMapClientTemplate().delete("DefaultCarefullyChosenItemsDao.delete",id) > 0;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CarefullyChosenItems> getCarefullyChosenItems(int start,int end,long categoryLevel1,long categoryLevel2){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("start", start);
		map.put("end", end);
		map.put("categoryLevel1", categoryLevel1);
		map.put("categoryLevel2", categoryLevel2);
		return getSqlMapClientTemplate().queryForList("DefaultCarefullyChosenItemsDao.getCarefullyChosenItems",map);
	}

}
